package b.p.b;

import android.view.View;
import androidx.recyclerview.widget.RecyclerView.m;

/* compiled from: LinearSnapHelper */
public class u extends e0 {
    public z d;
    public z e;

    public int[] a(m mVar, View view) {
        int[] iArr = new int[2];
        if (mVar.g()) {
            iArr[0] = d(view, g(mVar));
        } else {
            iArr[0] = 0;
        }
        if (mVar.h()) {
            iArr[1] = d(view, h(mVar));
        } else {
            iArr[1] = 0;
        }
        return iArr;
    }

    public View b(m mVar) {
        if (mVar.h()) {
            return f(mVar, h(mVar));
        }
        return mVar.g() ? f(mVar, g(mVar)) : null;
    }

    public final int d(View view, z zVar) {
        return ((zVar.c(view) / 2) + zVar.e(view)) - ((zVar.l() / 2) + zVar.k());
    }

    public final int e(m mVar, z zVar, int i, int i2) {
        r0 = new int[2];
        this.b.fling(0, 0, i, i2, Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.MIN_VALUE, Integer.MAX_VALUE);
        r0[0] = this.b.getFinalX();
        r0[1] = this.b.getFinalY();
        i = mVar.A();
        float f = 1.0f;
        if (i != 0) {
            View view = null;
            View view2 = null;
            int i3 = Integer.MAX_VALUE;
            int i4 = Integer.MIN_VALUE;
            for (int i5 = 0; i5 < i; i5++) {
                View z = mVar.z(i5);
                int S = mVar.S(z);
                if (S != -1) {
                    if (S < i3) {
                        view = z;
                        i3 = S;
                    }
                    if (S > i4) {
                        view2 = z;
                        i4 = S;
                    }
                }
            }
            if (!(view == null || view2 == null)) {
                int max = Math.max(zVar.b(view), zVar.b(view2)) - Math.min(zVar.e(view), zVar.e(view2));
                if (max != 0) {
                    f = (((float) max) * 1.0f) / ((float) ((i4 - i3) + 1));
                }
            }
        }
        if (f <= 0.0f) {
            return 0;
        }
        return Math.round(((float) (Math.abs(r0[0]) > Math.abs(r0[1]) ? r0[0] : r0[1])) / f);
    }

    public final View f(m mVar, z zVar) {
        int A = mVar.A();
        View view = null;
        if (A == 0) {
            return null;
        }
        int l = (zVar.l() / 2) + zVar.k();
        int i = Integer.MAX_VALUE;
        for (int i2 = 0; i2 < A; i2++) {
            View z = mVar.z(i2);
            int abs = Math.abs(((zVar.c(z) / 2) + zVar.e(z)) - l);
            if (abs < i) {
                view = z;
                i = abs;
            }
        }
        return view;
    }

    public final z g(m mVar) {
        z zVar = this.e;
        if (zVar == null || zVar.a != mVar) {
            this.e = new x(mVar);
        }
        return this.e;
    }

    public final z h(m mVar) {
        z zVar = this.d;
        if (zVar == null || zVar.a != mVar) {
            this.d = new y(mVar);
        }
        return this.d;
    }
}
